package com.zb.internetSpider.gui.tree.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class NzNode extends AbstractTreeNode implements TreeNode {
	// 节点编号
	private String id;

	// 节点文本
	private String name;

	// 节点是否选中
	private boolean checked;

	// 节点是否可选
	private boolean disableCheckbox;

	// 若节点下有子节点，子节点的checked都为true的和都不为true的时候值为false,否则为true
	private boolean halfChecked;

	// 是否启动异步加载子节点
	private boolean hasChildren;

	private String pId;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	public boolean isDisableCheckbox() {
		return disableCheckbox;
	}

	public void setDisableCheckbox(boolean disableCheckbox) {
		this.disableCheckbox = disableCheckbox;
	}

	public boolean getHalfChecked() {
		return halfChecked;
	}

	public void setHalfChecked(boolean halfChecked) {
		this.halfChecked = halfChecked;
	}

	public boolean getHasChildren() {
		return hasChildren;
	}

	public void setHasChildren(boolean hasChildren) {
		this.hasChildren = hasChildren;
	}

	@Override
	public String getpId() {
		// TODO Auto-generated method stub
		return pId;
	}

	@Override
	public void setpId(String pId) {
		// TODO Auto-generated method stub
		this.pId = pId;
	}

	@Override
	public Integer getLevel() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setLevel(Integer level) {
		// TODO Auto-generated method stub

	}

	public NzNode clone() {
		try {
			return (NzNode) super.clone();
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 深拷贝
	 * 
	 * @return
	 */
	public NzNode deepClone() {
		NzNode node = null;
		try {
			// 写入字节流
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			ObjectOutputStream obs = new ObjectOutputStream(out);
			obs.writeObject(this);
			obs.close();

			// 分配内存，写入原始对象，生成新对象
			ByteArrayInputStream ios = new ByteArrayInputStream(out.toByteArray());
			ObjectInputStream ois = new ObjectInputStream(ios);
			// 返回生成的新对象
			node = (NzNode) ois.readObject();
			ois.close();
		} catch (IOException e) {
			// TODO: handle exception
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return node;
	}

}
